﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.DS
{
    public static partial class classes
    {
        public static dynamic addOrEdiClass(int? cid, string title)
        {
            var sql = new Sql.SqlDataContext();

            Sql.DSClass c;
            if (cid == null) // Add
            {
                c = new Sql.DSClass();
            }
            else // Modify
            {
                c = sql.DSClass.FirstOrDefault(row => row.cid == cid);
                if (c == null) return new
                {
                    success = false,
                    msg = "班级不存在"
                };
            }
            c.title = title;
            if (cid == null) sql.DSClass.InsertOnSubmit(c);
            sql.SubmitChanges();
            return new
            {
                success = true,
                c.cid
            };
        }
    }
}
